home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / gcc260utilsdoc.lha / gnu / man / man1 / grep.1 < prev    next >
Encoding:
Text File  |  1994-07-28  |  9.4 KB  |  265 lines

  1.  
  2.  
  3.  
  4. GREP(1)                  USER COMMANDS                    GREP(1)
  5.  
  6.  
  7.  
  8. NAME
  9.      grep, egrep, fgrep - print lines matching a pattern
  10.  
  11. SYNOPOSIS
  12.      grep [ -[[AB] ]_n_u_m ] [ -[CEFGVBchilnsvwx] ] [ -e ] _p_a_t_t_e_r_n |
  13.      -f_f_i_l_e ] [ _f_i_l_e_s... ]
  14.  
  15. DESCRIPTION
  16.      Grep searches the named input _f_i_l_e_s (or standard input if no
  17.      files are named, or the file name - is given) for lines con-
  18.      taining a match to the  given  _p_a_t_t_e_r_n.   By  default,  grep
  19.      prints the matching lines.
  20.  
  21.      There are three major variants of grep,  controlled  by  the
  22.      following options.
  23.      -G   Interpret _p_a_t_t_e_r_n as a basic  regular  expression  (see
  24.           below).  This is the default.
  25.      -E   Interpret _p_a_t_t_e_r_n as  an  extended  regular  expression
  26.           (see below).
  27.      -F   Interpret _p_a_t_t_e_r_n as a list of fixed strings, separated
  28.           by newlines, any of which is to be matched.
  29.      In addition, two variant programs egrep and fgrep are avail-
  30.      able.  Egrep is similiar (but not identical) to grep -E, and
  31.      is compatible with the historical Unix egrep.  Fgrep is  the
  32.      same as grep -F.
  33.  
  34.      All variants of grep understand the following options:
  35.      -_n_u_m Matches will be printed with _n_u_m lines of  leading  and
  36.           trailing  context.   However, grep will never print any
  37.           given line more than once.
  38.      -A _n_u_m
  39.           Print _n_u_m lines  of  trailing  context  after  matching
  40.           lines.
  41.      -B _n_u_m
  42.           Print _n_u_m lines  of  leading  context  before  matching
  43.           lines.
  44.      -C   Equivalent to -2.
  45.      -V   Print the version number of  grep  to  standard  error.
  46.           This  version  number  should  be  included  in all bug
  47.           reports (see below).
  48.      -b   Print the byte offset within the input file before each
  49.           line of output.
  50.      -c   Suppress normal output; instead print a count of match-
  51.           ing lines for each input file.  With the -v option (see
  52.           below), count non-matching lines.
  53.      -e _p_a_t_t_e_r_n
  54.           Use _p_a_t_t_e_r_n as the pattern; useful to protect  patterns
  55.           beginning with -.
  56.      -f _f_i_l_e
  57.           Obtain the pattern from _f_i_l_e.
  58.      -h   Suppress the prefixing of filenames on output when mul-
  59.           tiple files are searched.
  60.  
  61.  
  62.  
  63. GNU Project      Last change: 1992 September 10                 1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GREP(1)                  USER COMMANDS                    GREP(1)
  71.  
  72.  
  73.  
  74.      -i   Ignore case distinctions in both the  _p_a_t_t_e_r_n  and  the
  75.           input files.
  76.      -L   Suppress normal output; instead print the name of  each
  77.           input  file  from  which  no output would normally have
  78.           been printed.
  79.      -l   Suppress normal output; instead print the name of  each
  80.           input  file  from which output would normally have been
  81.           printed.
  82.      -n   Prefix each line of output with the line number  within
  83.           its input file.
  84.      -q   Quiet; suppress normal output.
  85.      -s   Suppress error messages about nonexistent or unreadable
  86.           files.
  87.      -v   Invert the sense of matching,  to  select  non-matching
  88.           lines.
  89.      -w   Select only those lines containing  matches  that  form
  90.           whole  words.   The test is that the matching substring
  91.           must either be at the beginning of the  line,  or  pre-
  92.           ceded  by a non-word constituent character.  Similarly,
  93.           it must be either at the end of the line or followed by
  94.           a  non-word  constituent  character.   Word-constituent
  95.           characters are letters, digits, and the underscore.
  96.      -x   Select only those matches that exactly match the  whole
  97.           line.
  98.  
  99. REGULAR EXPRESSIONS
  100.      A regular expression is a pattern that describes  a  set  of
  101.      strings.  Regular expressions are constructed analagously to
  102.      arithmetic expressions, by using various operators  to  com-
  103.      bine smaller expressions.
  104.  
  105.      Grep understands two different versions of  regular  expres-
  106.      sion syntax: ``basic'' and ``extended.''  In GNU grep, there
  107.      is no difference in  available  functionality  using  either
  108.      syntax.  In other implementations, basic regular expressions
  109.      are less powerful.  The  following  description  applies  to
  110.      extended  regular expressions; differences for basic regular
  111.      expressions are summarized afterwards.
  112.  
  113.      The fundamental building blocks are the regular  expressions
  114.      that  match  a single character.  Most characters, including
  115.      all letters and digits, are regular expressions  that  match
  116.      themselves.   Any  metacharacter with special meaning may be
  117.      quoted by preceding it with a backslash.
  118.  
  119.      A list of characters enclosed by [ and ] matches any  single
  120.      character  in  that list; if the first character of the list
  121.      is the caret ^ then it matches  any  character  _n_o_t  in  the
  122.      list.   For  example,  the  regular  expression [0123456789]
  123.      matches any single digit.  A range of ASCII  characters  may
  124.      be  specified  by  giving  the  first  and  last characters,
  125.      separated by a hyphen.  Finally, certain  named  classes  of
  126.  
  127.  
  128.  
  129. GNU Project      Last change: 1992 September 10                 2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. GREP(1)                  USER COMMANDS                    GREP(1)
  137.  
  138.  
  139.  
  140.      characters  are  predefined.   Their names are self explana-
  141.      tory,  and  they  are   [:alnum:],   [:alpha:],   [:cntrl:],
  142.      [:digit:],   [:graph:],   [:lower:],  [:print:],  [:punct:],
  143.      [:space:],  [:upper:],   and   [:xdigit:].    For   example,
  144.      [[:alnum:]]  means  [0-9A-Za-z],  except  the latter form is
  145.      dependent upon the ASCII  character  encoding,  whereas  the
  146.      former  is portable.  (Note that the brackets in these class
  147.      names are part of the symbolic names, and must  be  included
  148.      in  addition  to  the brackets delimiting the bracket list.)
  149.      Most metacharacters lose their special meaning inside lists.
  150.      To  include  a  literal ] place it first in the list.  Simi-
  151.      larly, to include a literal ^ place it anywhere  but  first.
  152.      Finally, to include a literal - place it last.
  153.  
  154.      The period . matches any single character.  The symbol \w is
  155.      a   synonym   for  [[:alnum:]]  and  \W  is  a  synonym  for
  156.      [^[:alnum]].
  157.  
  158.      The caret ^ and the dollar sign $  are  metacharacters  that
  159.      respectively match the empty string at the beginning and end
  160.      of a line.  The symbols \< and  \>  respectively  match  the
  161.      empty string at the beginning and end of a word.  The symbol
  162.      \b matches the empty string at the edge of a  word,  and  \B
  163.      matches  the empty string provided it's _n_o_t at the edge of a
  164.      word.
  165.  
  166.      A regular expression matching a single character may be fol-
  167.      lowed by one of several repetition operators:
  168.      ?    The preceding item is  optional  and  matched  at  most
  169.           once.
  170.      *    The preceding item will be matched zero or more times.
  171.      +    The preceding item will be matched one or more times.
  172.      {_n}  The preceding item is matched exactly _n times.
  173.      {_n,} The preceding item is matched _n or more times.
  174.      {,_m} The preceding item is optional and is matched at most _m
  175.           times.
  176.      {_n,_m}
  177.           The preceding item is matched at least _n times, but not
  178.           more than _m times.
  179.  
  180.      Two regular expressions may be concatenated;  the  resulting
  181.      regular  expression matches any string formed by concatenat-
  182.      ing two substrings that respectively match the  concatenated
  183.      subexpressions.
  184.  
  185.      Two regular expressions may be joined by the infix  operator
  186.      |;  the  resulting  regular  expression  matches  any string
  187.      matching either subexpression.
  188.  
  189.      Repetition takes precedence  over  concatenation,  which  in
  190.      turn  takes precedence over alternation.  A whole subexpres-
  191.      sion may  be  enclosed  in  parentheses  to  override  these
  192.  
  193.  
  194.  
  195. GNU Project      Last change: 1992 September 10                 3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. GREP(1)                  USER COMMANDS                    GREP(1)
  203.  
  204.  
  205.  
  206.      precedence rules.
  207.  
  208.      The backreference \_n, where _n is a single digit, matches the
  209.      substring previously matched by the _nth parenthesized subex-
  210.      pression of the regular expression.
  211.  
  212.      In basic regular expressions the metacharacters ?, +, {,  |,
  213.      (,  and  )  lose  their  special  meaning;  instead  use the
  214.      backslashed versions \?, \+, \{, \|, \(, and \).
  215.  
  216.      In egrep the metacharacter  {  loses  its  special  meaning;
  217.      instead use \{.
  218.  
  219. DIAGNOSTICS
  220.      Normally, exit status is 0 if matches were found, and  1  if
  221.      no  matches were found.  (The -v option inverts the sense of
  222.      the exit status.) Exit status is  2  if  there  were  syntax
  223.      errors  in  the  pattern, inaccessible input files, or other
  224.      system errors.
  225.  
  226. BUGS
  227.      Email bug reports to bug-gnu-utils@prep.ai.mit.edu.  Be sure
  228.      to  include  the word ``grep'' somewhere in the ``Subject:''
  229.      field.
  230.  
  231.      Large repetition counts in the  {_m,_n}  construct  may  cause
  232.      grep  to  use  lots  of  memory.  In addition, certain other
  233.      obscure regular expressions  require  exponential  time  and
  234.      space, and may cause grep to run out of memory.
  235.  
  236.      Backreferences are very slow, and  may  require  exponential
  237.      time.
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. GNU Project      Last change: 1992 September 10                 4
  262.  
  263.  
  264.  
  265.